package com.controller;

import com.dto.ActivityDTO;
import com.dto.DonationDTO;
import com.dto.NoticeDTO;
import com.service.DonationServiceImpl;
import com.service.LoginServiceImpl;
import com.service.NoticeServiceImpl;
import com.util.Result;
import com.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linyukun
 * @date 2022/10/9 9:13
 */
@RequestMapping("notice")
@RestController
public class NoticeController {
    @Autowired
    private NoticeServiceImpl noticeServiceImpl;

    @Autowired
    private LoginServiceImpl loginServiceImpl;

    /**
     * 新增通告信息
     * @author linyukun
     * @date 2022-10-09 10:58:00
     */
    @RequestMapping(value="/addNotice",method = RequestMethod.POST)
    public Result addNotice(@RequestBody NoticeDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setCreateUser(userName);
            return ResultUtil.returnDataSuccess(noticeServiceImpl.addNotice(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 删除通告信息
     * @author linyukun
     * @date 2022-10-09 11:00:00
     */
    @RequestMapping(value="/delNotice",method = RequestMethod.POST)
    public Result delNotice(@RequestBody NoticeDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setDeleteUser(userName);
            return ResultUtil.returnDataSuccess(noticeServiceImpl.delNotice(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 修改通告信息
     * @author linyukun
     * @date 2022-10-09 11:00:00
     */
    @RequestMapping(value="/updateNotice",method = RequestMethod.POST)
    public Result updateNotice(@RequestBody NoticeDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setUpdateUser(userName);
            return ResultUtil.returnDataSuccess(noticeServiceImpl.updateNotice(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 获取通告信息列表
     * @author linyukun
     * @date 2022-10-09 11:05:00
     */
    @RequestMapping(value="/getNoticeList",method = RequestMethod.POST)
    public Result getDonationList(@RequestBody NoticeDTO dto){
        try{
            loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(noticeServiceImpl.getNoticeList(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 发布通告
     * @author linyukun
     * @date 2022-10-08 18:00:00
     */
    @RequestMapping(value="/publishNotice",method = RequestMethod.POST)
    public Result publishNotice(@RequestBody NoticeDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(noticeServiceImpl.publishNotice(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

}
